/*
 * StatsWindow.java
 *
 * Copyright (C) 2011 Thomas Everingham
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * A copy of the GNU General Public License can be found in the file
 * LICENSE.txt provided with the source distribution of this program (see
 * the META-INF directory in the source jar). This license can also be
 * found on the GNU website at http://www.gnu.org/licenses/gpl.html.
 *
 * If you did not receive a copy of the GNU General Public License along
 * with this program, contact the lead developer, or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 * If you find this program useful, please tell me about it! I would be delighted
 * to hear from you at tom.ingatan@gmail.com.
 */

package org.ingatan.component.statcentre;

import java.awt.Dimension;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
import org.ingatan.ThemeConstants;

/**
 * A statistics window with a sidebar and content pane. Allows the user to view
 * quiz history, as well as graphical statistics of quiz results for selected
 * libraries and flashcard type questions. Also holds the RewardsPane.
 *
 * @author Thomas Everingham
 * @version 1.0
 */
public class StatsWindow extends javax.swing.JFrame implements WindowListener {

    /** The QuizHistoryPane displayed by this stats window */
    QuizHistoryPane historyPane = new QuizHistoryPane();

    /** The LibraryStatsGraphPane displayed by this stats window */
    LibraryGraphsPane libStatsPane = new LibraryGraphsPane();

    /** Rewards pane displayed by this stats window */
    RewardsPane rewardsPane = new RewardsPane();

    /** Flashcard scatter pane displayed by this stats window */
    FlashcardScatterPane scatterPane = new FlashcardScatterPane();

    JFrame returnToOnClose;

    /** Creates new form StatsWindow */
    public StatsWindow(JFrame returnToOnClose) {
        initComponents();
        this.setSize(new Dimension(1000,500));
        this.setLocationRelativeTo(null);
        this.returnToOnClose = returnToOnClose;
        this.addWindowListener(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblHeading = new javax.swing.JLabel();
        horiz = new javax.swing.JPanel();
        menuPanel = new javax.swing.JPanel();
        btnQuizHistory = new javax.swing.JButton();
        btnLibraryGraphs = new javax.swing.JButton();
        btnFlashcardScatter = new javax.swing.JButton();
        btnRewards = new javax.swing.JButton();
        contentPane = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Statistics Centre");
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));

        lblHeading.setText("Statistics and History");
        lblHeading.setFont(ThemeConstants.hugeFont.deriveFont(26.0f));
        lblHeading.setForeground(ThemeConstants.textColour);
        getContentPane().add(lblHeading);

        horiz.setAlignmentX(0.0F);
        horiz.setLayout(new javax.swing.BoxLayout(horiz, javax.swing.BoxLayout.LINE_AXIS));

        menuPanel.setAlignmentY(0.05F);
        menuPanel.setMaximumSize(new java.awt.Dimension(150, 200));
        menuPanel.setPreferredSize(new java.awt.Dimension(150, 450));
        menuPanel.setLayout(new java.awt.GridLayout(5, 0, 0, 10));

        btnQuizHistory.setText("Quiz History");
        btnQuizHistory.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnQuizHistoryActionPerformed(evt);
            }
        });
        menuPanel.add(btnQuizHistory);

        btnLibraryGraphs.setText("Library Graphs");
        btnLibraryGraphs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLibraryGraphsActionPerformed(evt);
            }
        });
        menuPanel.add(btnLibraryGraphs);

        btnFlashcardScatter.setText("Flashcards");
        btnFlashcardScatter.setActionCommand("Flashcards");
        btnFlashcardScatter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFlashcardScatterActionPerformed(evt);
            }
        });
        menuPanel.add(btnFlashcardScatter);

        btnRewards.setText("Rewards Game");
        btnRewards.setActionCommand("Rewards Game");
        btnRewards.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRewardsActionPerformed(evt);
            }
        });
        menuPanel.add(btnRewards);

        horiz.add(menuPanel);

        javax.swing.GroupLayout contentPaneLayout = new javax.swing.GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 980, Short.MAX_VALUE)
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 429, Short.MAX_VALUE)
        );

        horiz.add(contentPane);

        getContentPane().add(horiz);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnLibraryGraphsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLibraryGraphsActionPerformed
        contentPane.remove(historyPane);
        contentPane.remove(rewardsPane);
        contentPane.remove(scatterPane);
        contentPane.add(libStatsPane);
        contentPane.validate();
        contentPane.repaint();
    }//GEN-LAST:event_btnLibraryGraphsActionPerformed

    private void btnQuizHistoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuizHistoryActionPerformed
        contentPane.remove(libStatsPane);
        contentPane.remove(rewardsPane);
        contentPane.remove(scatterPane);
        contentPane.add(historyPane);
        contentPane.validate();
        contentPane.repaint();
    }//GEN-LAST:event_btnQuizHistoryActionPerformed

    private void btnRewardsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRewardsActionPerformed
        contentPane.remove(libStatsPane);
        contentPane.remove(historyPane);
        contentPane.remove(scatterPane);
        contentPane.add(rewardsPane);
        contentPane.validate();
        contentPane.repaint();
    }//GEN-LAST:event_btnRewardsActionPerformed

    private void btnFlashcardScatterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFlashcardScatterActionPerformed
        contentPane.remove(historyPane);
        contentPane.remove(rewardsPane);
        contentPane.remove(libStatsPane);
        contentPane.add(scatterPane);
        contentPane.validate();
        contentPane.repaint();
    }//GEN-LAST:event_btnFlashcardScatterActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnFlashcardScatter;
    private javax.swing.JButton btnLibraryGraphs;
    private javax.swing.JButton btnQuizHistory;
    private javax.swing.JButton btnRewards;
    private javax.swing.JPanel contentPane;
    private javax.swing.JPanel horiz;
    private javax.swing.JLabel lblHeading;
    private javax.swing.JPanel menuPanel;
    // End of variables declaration//GEN-END:variables

    public void windowOpened(WindowEvent e) {
    }

    public void windowClosing(WindowEvent e) {
        returnToOnClose.setVisible(true);
    }

    public void windowClosed(WindowEvent e) {
    }

    public void windowIconified(WindowEvent e) {
    }

    public void windowDeiconified(WindowEvent e) {
    }

    public void windowActivated(WindowEvent e) {
    }

    public void windowDeactivated(WindowEvent e) {
    }

}
